import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import { createApp } from 'vue'
import App from './App.vue'
import './assets/font/iconfont.css'
import i18n from './i18n'
import './style.css'

import './demos/ipc'
// If you want use Node.js, the`nodeIntegration` needs to be enabled in the Main process.
// import './demos/node'

import { createRouter, createWebHashHistory } from 'vue-router'
import routes from './router/routes'
import { request } from './utils/request'

const router = createRouter({
  history: createWebHashHistory(),
  routes,
})

// 应用启动时清除首页数据缓存（确保重新打开应用时获取最新数据）
// 通过检查是否有 appStarted 标记来判断是否是重新启动
const isAppRestart = !sessionStorage.getItem('appStarted')
if (isAppRestart) {
  sessionStorage.removeItem('indexData')
  sessionStorage.removeItem('indexDataTimestamp')
  sessionStorage.setItem('appStarted', 'true')
  console.log('应用重新启动，已清除首页数据缓存')
}


// 开机自启

// 关闭自启
// myAppLauncher.disable()

const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}
app.use(router)
app.use(i18n)
app.config.globalProperties.$request = request
app.use(ElementPlus)

app.mount('#app')
.$nextTick(() => {
  postMessage({ payload: 'removeLoading' }, '*')
})
